import {createAction, createThunkAction} from "../../lib/redux-utils";
import {get, postJson} from "../../lib/http";
import {getPrincipal} from "../../lib/identity";

const principal = getPrincipal();
const path = "/notice";
const ACTION_PREFIX = "NOTICE.";
export const query = createThunkAction(ACTION_PREFIX + "QUERY", params =>
    postJson(path + "/query", params)
);
export const showCreate = createAction(ACTION_PREFIX + "SHOW_CREATE");
export const hideCreate = createAction(ACTION_PREFIX + "HIDE_CREATE");
export const showModify = createAction(ACTION_PREFIX + "SHOW_MODIFY");
export const hideModify = createAction(ACTION_PREFIX + "HIDE_MODIFY");

export const create = createThunkAction(ACTION_PREFIX + "CREATE", params =>
    postJson(path + "/create", params)
);
export const update = createThunkAction(ACTION_PREFIX + "MODIFY", params =>
    postJson(path + "/update", params)
);
export const del = createThunkAction(ACTION_PREFIX + "DELETE", params =>
    get(path + "/delete/" + params + "/" + principal.id)
);